<!--
* 添加页面
* @author chenyi
* @email qq228112142@qq.com
* @date 2017-08-10 08:56:33
*-->
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@ include file="/common/jsp/resource.jsp" %>
</head>
<body>
<div class="layui-field-box">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">支付方式编码<span class="span_must">*</span></label>
            <div class="layui-input-normal">
                <input type="text" name="code"  maxlength="16"  lay-verify="required" placeholder="请输入支付方式编码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">支付方式名称<span class="span_must">*</span></label>
            <div class="layui-input-normal">
                <input type="text" name="name" maxlength="50"  lay-verify="required" placeholder="请输入支付方式名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">支持WEB支付<span class="span_must">*</span></label>
            <div class="layui-input-normal">
                <div cyType="radioTool" cyProps="codeName:'support'" name="supportWeb"
                     value="1" class="layui-input-inline"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">支付方式图标<span class="span_must">*</span></label>
            <div class="site-demo-upload">
                <div class="site-demo-upload" style="margin: 10px 20px 20px 20px;">
                    <input type="file" name="file" class="layui-upload-file" id="img"  >
                </div>
                <img id="LAY_demo_upload"  style="max-height:500px;max-width:800px;margin-left:120px;" src="">
                <input type="hidden" lay-verify="img"  id="img_url" name="img" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
                <button class="layui-btn" onclick="closeWindow()"> 返回</button>
            </div>
        </div>
    </form>
</div>
<script>
    //图片上传
    layui.use('upload', function () {
        var index;
        layui.upload({
            url: '/payway/upload'
            , elem: '#img' //指定原始元素，默认直接查找class="layui-upload-file"
            , method: 'post' //上传接口的http类型
            , before: function (input) {//上传前
                index = layer.load(0, {shade: [0.1, '#000']});
            }
            , success: function (res) {
                LAY_demo_upload.src = res.url;
                $("#img_url").val(res.url);
                layer.close(index);
            }
        });
    });

    layui.use(['form'], function () {
        var form = layui.form();
        //监听提交
        form.on('submit(submit)', function (data) {
            $.ajax({
                url: "/payway/save",
                type: "post",
                contentType: "application/json",
                data: JSON.stringify(data.field),
                async: false,
                dataType: "json",
                success: function (R) {
                    if (R.code === 0) {
                        alert('操作成功', function (index) {
                            closeWindow();
                        });
                    } else {
                        alert(R.msg);
                    }
                },
                error: function () {
                    alert("系统繁忙");
                }
            });
            return false;
        });

        /**验证是否有上传图片**/
        form.verify({
            img: function (value, item) { //
                debugger;
                if (value=="") {
                    return '请上传支付方式图标!';
                }
            }
        });
    });
</script>
</body>
</html>
